using System;

namespace TXK
{
	public static class CounterLib
	{
		public static ushort FromByteArray(byte[] bytes)
		{
			return CounterLib.FromBytes(bytes[1], bytes[0]);
		}

		public static ushort FromBytes(byte LoVal, byte HiVal)
		{
			return (ushort)(HiVal * 256 + LoVal);
		}

		public static byte[] ToByteArray(ushort value)
		{
			byte[] array;
			array = new byte[2];
			int num;
			num = 2;
			long num2;
			num2 = value;
			for (int i = 0; i < num; i++)
			{
				long num3;
				num3 = (long)Math.Pow(256.0, i);
				array[num - i - 1] = (byte)((num2 / num3) & 0xFF);
				num2 -= array[num - i - 1] * num3;
			}
			return array;
		}

		public static byte[] ToByteArray(ushort[] value)
		{
			ByteArray byteArray;
			byteArray = new ByteArray();
			for (int i = 0; i < value.Length; i++)
			{
				byteArray.Add(CounterLib.ToByteArray(value[i]));
			}
			return byteArray.array;
		}

		public static ushort[] ToArray(byte[] bytes)
		{
			ushort[] array;
			array = new ushort[bytes.Length / 2];
			int num;
			num = 0;
			for (int i = 0; i < bytes.Length / 2; i++)
			{
				array[i] = CounterLib.FromByteArray(new byte[2]
				{
					bytes[num++],
					bytes[num++]
				});
			}
			return array;
		}
	}
}
